package com.tianyalei.wolf.mddesignlib.snackbar;

import android.support.design.widget.Snackbar;
import android.view.View;

/**
 * Created by wolf on 2016/3/7.
 * Snackbar工具类
 */
public class AbSnackBarUtil {
    /**
     * 显示普通的SnackBar
     * @param view
     * @param msg
     */
    public static void showSnackBar(View view, String msg) {
        getSnackbar(view, msg).show();
    }

    /**
     * 显示带action的snackBar
     * @param view
     * @param msg
     * @param actionName
     */
    public static void showSnackBarAction(View view, String msg, String actionName, final SnackClickListener listener) {
        Snackbar.make(view, msg, Snackbar.LENGTH_LONG)
                .setAction(actionName, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (listener != null)
                            listener.action();
                    }
                }).show();
    }

    public static void showAlertSnackBar(View view, String msg) {
        ColoredSnackbar.alert(getSnackbar(view, msg)).show();
    }

    public static void showWarningSnackBar(View view, String msg) {
        ColoredSnackbar.warning(getSnackbar(view, msg)).show();
    }

    public static void showInfoSnackBar(View view, String msg) {
        ColoredSnackbar.info(getSnackbar(view, msg)).show();
    }

    public static void showConfirmSnackBar(View view, String msg) {
        ColoredSnackbar.confirm(getSnackbar(view, msg)).show();
    }

    /**
     * 制作SnackBar
     * @param view
     * @param msg
     * @return
     */
    private static Snackbar getSnackbar(View view, String msg) {
        return Snackbar.make(view, msg, Snackbar.LENGTH_SHORT);
    }

    public interface SnackClickListener {
        void action();
    }
}
